//
// Created by 17775 on 2024/6/21.
//

#ifndef RAYCI_POWERPROFILE_H
#define RAYCI_POWERPROFILE_H

#include "../qcustomplot.h"
#include "../utils/PowerProfileDataReceiveListener.h"
#include "../utils/ticktock.hpp"

QT_BEGIN_NAMESPACE
namespace Ui { class PowerProfile; }
QT_END_NAMESPACE

class PowerProfile : public QDockWidget, public PowerProfileDataReceiveListener {
Q_OBJECT

signals:
    void stopNewPowerProfileThread();
    void showPowerProfileSettings();

public:
    explicit PowerProfile(QWidget *parent = nullptr);
    ~PowerProfile() override;
    void closeEvent(QCloseEvent *event);

    int getOrder() const override {
        return 100;
    }
    void receiveMessage(const std::shared_ptr<PowerProfileData<std::vector<float>>>& data) override;
    static QList<double> convertVectorToQList(const std::vector<float>& vec);
    void closePowerProfile();
    void refreshViewRange();
    void setCursorPos(double pos);
    void refreshCustomPlot();
    void setCursorPosition(double pos);
    void changeXUnit(const QString& unit);
    void showAbscissa(bool show);
    void showOrdinate(bool show);
    void setTitle(double d, double pc);
    void setWindowTitleName(const QString& name);

private:
    Ui::PowerProfile *ui;
    QCPTextElement *title = nullptr;
    QCustomPlot *customPlot = nullptr;
    QMenu *m_contextMenu = nullptr;
    QCPItemLine *verticalLine = nullptr;

    double preCursorPos = 0;
    double cursorPos = 0;
    bool firstRescale = true;
};


#endif //RAYCI_POWERPROFILE_H
